package com.evil.application.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.evil.application.pojo.dto.form.control.related.ControlRelatedDTO;
import com.evil.application.pojo.entity.ApplicationFormControlRelated;
import com.evil.common.core.exception.BusinessException;
import com.evil.common.db.mapper.BatchMapper;
import com.evil.common.family.enums.RCodeEnum;
import org.apache.ibatis.annotations.Param;

import java.util.Collection;
import java.util.List;
import java.util.Optional;

/**
 * 应用表单控件关联表
 *
 * @author liyang
 * @date 2023-09-25 15:14
 */
public interface ApplicationFormControlRelatedMapper extends BaseMapper<ApplicationFormControlRelated>, BatchMapper<ApplicationFormControlRelated, Long> {

    int updateBatch(List<ApplicationFormControlRelated> list);

    int batchInsert(@Param("list") List<ApplicationFormControlRelated> list);

    default Optional<ApplicationFormControlRelated> isExistById(Long id) {
        return Optional.ofNullable(this.selectById(id));
    }

    default ApplicationFormControlRelated findById(Long id) {
        return this.isExistById(id).orElseThrow(() -> new BusinessException(RCodeEnum.CONTROL_CONTROL_RELATED_NOT_EXIST));
    }

    List<ApplicationFormControlRelated> findByIds(@Param("ids") Collection<Long> ids, @Param("filterDeleted") boolean filterDeleted);

    /**
     * 获取控件关联
     *
     * @param controlId     controlId
     * @param filterDeleted filterDeleted
     * @return ControlRelatedDTO 列表
     */
    List<ApplicationFormControlRelated> findByControlId(@Param("controlId") Long controlId, @Param("filterDeleted") boolean filterDeleted);

    /**
     * 获取控件关联
     *
     * @param controlIds    controlIds
     * @param filterDeleted filterDeleted
     * @return ControlRelatedDTO 列表
     */
    List<ApplicationFormControlRelated> findByControlIds(@Param("controlIds") Collection<Long> controlIds, @Param("filterDeleted") boolean filterDeleted);

    /**
     * 获取控件关联
     *
     * @param controlId     controlId
     * @param filterDeleted filterDeleted
     * @return ControlRelatedDTO 列表
     */
    List<ControlRelatedDTO> findBaseByControlId(@Param("controlId") Long controlId, @Param("filterDeleted") boolean filterDeleted);

    /**
     * 获取控件关联
     *
     * @param controlIds    controlIds
     * @param filterDeleted filterDeleted
     * @return ControlRelatedDTO 列表
     */
    List<ControlRelatedDTO> findBaseByControlIds(@Param("controlIds") Collection<Long> controlIds, @Param("filterDeleted") boolean filterDeleted);
}
